package util;

import android.content.Context;
import android.media.MediaPlayer;

import com.tushikeji.facecar.application.PortableMonitorApplication;

import java.io.IOException;

/**
 * 创建日期：18-9-8 下午12:09
 * @author machong
 * @company
 * 文件名称： PlayConfBell.java
 * 类说明： 播放音频
 */
public class PlayConfBell {
    private final static String TAG = "PlayConfBell";
    private static MediaPlayer player;

    public static boolean playBell(int id) {
        Context m_context = App.getInstance();
        player = MediaPlayer.create(m_context, id);
        player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                // TODO Auto-generated method stub
                mp.release();
            }
        });
        try {
            if (player != null) {
                player.stop();
            }
            player.prepare();
            player.start();
        } catch (IllegalStateException e) {
            player.release();
            return false;
        } catch (IOException e) {
            player.release();
            return false;
        }

        return true;
    }
}
